$('.ajax-inner').attr("data-page","2");

$(window).scroll(function() {
	if($('.ajax-inner').attr("data-load") == 0) {
	  	if($(window).scrollTop() + $(window).height() + 1>= $(document).height()) {
			$('.ajax-load').show();
	        loadMoreData($('.ajax-inner').attr("data-page"));
	  	}
	}
});

function loadMoreData(page){
	var getType = window.location.href;
	if(getType.indexOf('=') > 0) {
		ajax_url = getType + "&page=" + page;
	} else {
		ajax_url = "?page=" + page;
	}
	$.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});
	$.ajax({
		url: ajax_url,
		type: "GET",
		complete:function(error) {
    	if (error['status']  === 500) {
    		console.log("服务器未响应");
    		}
  		},
		success:function(data){
			$('.ajax-load').hide();
			$('.ajax-inner').attr("data-page",parseInt($('.ajax-inner').attr("data-page"))+1);
			if(data['html'] == ""){
                $('.ajax-inner').append('<div class="mt-3 container text-center"><span>没有更多数据了</span></div>');
				$('.ajax-inner').attr("data-load", "1");
    		} else {
				$('.ajax-inner').append(data['html']);
    		}
		}
	})
};
